<template>
	<om-addpage style="padding-top: 35px;" :busCode="busCode" :menuName="menuName" @formSubmit="formSubmit">
		<om-autoform ref="autoform" :initConfigData="mainConfigData" :initValue="initValue"></om-autoform>
		<uni-list v-show="showload">
			<uni-list-item :showArrow="false">
				<view class="cont">
					<view class="fl"><span>*</span>拍照</view>
					<view class="fr" @tap="takePhone">
						<text class='cuIcon-cameraadd' style="color: rgb(0, 129, 255);font-size: 26px;"></text>
					</view>
				</view>
				<image mode="scaleToFill" :src="src" @tap="preview" style="width: 100px;height: 100px;background: #eaeaea;"></image>
			</uni-list-item>
			<uni-list-item :showArrow="false">
				<view class="cont tui-flex">
					<view class="fl tui-col-5">签到地址</view>
					<view class="fr tui-col-7" v-show="showmap" @tap="signPlace" style="color:#0081ff">{{ placeName }}</view>
				</view>
			</uni-list-item>
		</uni-list>
		<!-- #ifdef H5 -->
		<view v-show="!showmap && showload" class="map"></view>
		<view class="map" v-show="showmap && showload">
			<view id="container" class="map" @click="signPlace"></view>
			<!-- <map style="width: 100%; height: 100px;"
			 :latitude="placeLat" 
			 :longitude="placeLng" 
			 :markers="covers"
			 :enable-zoom="false"
			 :enable-scroll="false"
			 :scale="16"
			 @tap="signPlace"
			></map> -->
		</view>
		<!-- #endif -->
		<view style="position: absolute;top: -999999px;">
		    <view>
		        <canvas :style="{'width':w,'height': h}" canvas-id="firstCanvas"></canvas>
		   </view>
		</view>
		<!-- #ifdef APP || APP-PLUS || APP-NVUE || APP-PLUS-NVUE || APP-VUE -->
		<ot-authpup ref="authpup" type="top" @changeAuth="changeAuth" permissionID="ACCESS_FINE_LOCATION"></ot-authpup>
		<!-- #endif -->
	</om-addpage>
</template>
<script>
	// import AMapLoader from 'amaploader/@amap/amap-jsapi-loader';
	import {
		errorModal,
		ignoreHtml,
		getUrl,
		confirmModal,
		ptFloat,
		minusF
	} from '@/static/js/common.js';
	import {
		changeConfigAttr,
		buildFormData,
		formValidation,
		tranferToEditors,
		changeEditor,
		setSubmitSubValue,
		configSelectData,
		hasValue,
		formShowLoading,
		getFormFields,
		formModelLoad,
		getWorkCacheKey
	} from '@/static/js/formUtil.js';
	import urlUtil from '@/static/js/urlUtil.js';
	import { mapState } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
	
	
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildFormData({
				src: '',
				time: '',
				w:'',
				h:'',
				showmap: false,
				placeLng: '',
				placeLat: '',
				placeName: '',
				// customerNameIdCacheKey: 'mar-yxhd-visitSign-customernameid-cache',
				markerDesc: '',
				fileKey: '49',
				isnewcustomer: false,
				showload: false,
				covers: [],
				typeCacheKey: 'mar-yxhd-visitSign-title2-type-cache',
				customerObjIdCacheKey: 'mar-yxhd-visitSign-title2-customerObjId-cache',
				visitTargetIdStrCacheKey: 'mar-yxhd-visitSign-title2-visitTargetIdStr-cache',
				visitPreparationIdStrCacheKey: 'mar-yxhd-visitSign-title2-visitPreparationIdStr-cache',
				exchangePointIdStrCacheKey: 'mar-yxhd-visitSign-title2-exchangePointIdStr-cache',
				// visitPreparationListAll: [],
				haspic: false,
				visitShowIdCacheKey: 'mar-yxhd-visitSign-title2-visitShowId-cache',
				distanceValue: 500,
			})
		},
		computed: {
			...mapState(useLoginUserStore, ['userName', 'userId'])
		},
		methods:{
			clearVisitShow(){
				let _that = this;
				_that.$refs.autoform.clear('title2', 'visitShowId');
				_that.$refs.autoform.clear('title2', 'customerObjId');
				_that.$refs.autoform.clear('title2', 'customerId');
				_that.$refs.autoform.clear('title2', 'customerName');
				_that.$refs.autoform.clear('title2', 'customerShortName');
				_that.$refs.autoform.clear('title2', 'transactiontatus');
				_that.$refs.autoform.clear('title2', 'developmentDate');
				_that.$refs.autoform.clear('title2', 'transactiontatusId');
				_that.$refs.autoform.clear('title2', 'customerOwnerId');
				_that.$refs.autoform.clear('title2', 'instId');
				_that.$refs.autoform.clear('title2', 'planRemark');
				_that.$refs.autoform.clear('title2', 'typeId');
				_that.$refs.autoform.clear('title2', 'visitTargetIdStr');
				_that.$refs.autoform.clear('title2', 'visitPreparationIdStr');
				_that.$refs.autoform.clear('title2', 'startDate');
				_that.$refs.autoform.clear('title2', 'timeRangeId');
				_that.$refs.autoform.clear('title2', 'stopDate');
				_that.$refs.autoform.clear('title2', 'peopleId');
				_that.$refs.autoform.clear('title2', 'problemRemark');
				_that.$refs.autoform.clear('title2', 'orderDate');
			},
			clearCustomer(){
				let _that = this;
				_that.$refs.autoform.clear('title2', 'customerObjId');
				_that.$refs.autoform.clear('title2', 'customerId');
				_that.$refs.autoform.clear('title2', 'customerName');
				_that.$refs.autoform.clear('title2', 'customerShortName');
				_that.$refs.autoform.clear('title2', 'transactiontatus');
				_that.$refs.autoform.clear('title2', 'developmentDate');
				_that.$refs.autoform.clear('title2', 'transactiontatusId');
				_that.$refs.autoform.clear('title2', 'customerOwnerId');
				_that.$refs.autoform.clear('title2', 'instId');
				_that.$refs.autoform.clear('title2', 'planRemark');
				_that.$refs.autoform.clear('title2', 'typeId');
				_that.$refs.autoform.clear('title2', 'visitTargetIdStr');
				_that.$refs.autoform.clear('title2', 'visitPreparationIdStr');
				_that.$refs.autoform.clear('title2', 'startDate');
				_that.$refs.autoform.clear('title2', 'timeRangeId');
				_that.$refs.autoform.clear('title2', 'stopDate');
				_that.$refs.autoform.clear('title2', 'peopleId');
				_that.$refs.autoform.clear('title2', 'problemRemark');
				_that.$refs.autoform.clear('title2', 'orderDate');
			},
			initLoad(options){
				let _that = this
				let ajaxArr = [
					urlUtil.zposUrl(options.code),
					urlUtil.dataDictInitValueUrl('DD020019'), 
					// {
					// 	url:"tsysdict/getComboTree",
					// 	param:{
					// 		code:'39384'
					// 	}
					// }
					// urlUtil.sysdictComboboxUrl('39081'), //客户签到类型
				]
				
				formModelLoad(ajaxArr,function(res,mainData){
					_that.distanceValue = res[1].value
					changeEditor('topinfo', 'zposId', 'data', configSelectData(res[0], 'id', 'posname'), mainData);
					_that.$nextTick(function(){
						_that.$refs.autoform.initSelectVal("topinfo","zposId")
						_that.$refs.autoform.formdata.signInTime = _that.nowTime()
						_that.showload = true
					})
					// _that.visitPreparationListAll = res[1]
					if(_that.placeLng && _that.placeLat){
						// _that.showmap = true
					}else{
						//没有保存过数据获取浏览器定位
						// window.onLoad  = function(){
						setTimeout(() => {
							// #ifdef H5
						    var map = new AMap.Map('container',{
								zoom: 16, //设置地图的缩放级别
								zoomEnable: false,
								dragEnable: false,
								touchZoom: false,
							});
							
							AMap.plugin('AMap.Geolocation', function() {
							  var geolocation = new AMap.Geolocation({
							    // 是否使用高精度定位，默认：true
							    enableHighAccuracy: true,
							    // 设置定位超时时间，默认：无穷大
							    timeout: 3000,
							  })
							
							  geolocation.getCurrentPosition()
							  AMap.event.addListener(geolocation, 'complete', onComplete)
							  AMap.event.addListener(geolocation, 'error', onError)
							
							  function onComplete (data) {
								  console.log(data)
							    // data是具体的定位信息
								// var obj = _that.bd_decrypt(data.position.lng,data.position.lat)
								// _that.placeLng = obj.lng
								// _that.placeLat = obj.lat
								// _that.placeName = data.formattedAddress
								_that.placeLng = data.position.lng
								_that.placeLat = data.position.lat
								_that.placeName = data.formattedAddress
								
								if(_that.placeName){
									var cpoint = [_that.placeLng, _that.placeLat]; //中心点坐标
									map.panTo(cpoint);
									
									var marker = new AMap.Marker({
										position: new AMap.LngLat(_that.placeLng, _that.placeLat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
										title: _that.placeName
									});
									map.add(marker);
									
									_that.showmap = true
								}else{
									uni.request({
										url: 'https://restapi.amap.com/v3/geocode/regeo?output=JSON&location='+_that.placeLng+','+_that.placeLat+'&key=c45ef8eb1919b2e8feaeea26b9414942&radius=10&extensions=all',   
										success: (zres) => { 
											_that.placeName = zres.data.regeocode.formatted_address
											var cpoint = [_that.placeLng, _that.placeLat]; //中心点坐标
											map.panTo(cpoint);
											
											var marker = new AMap.Marker({
											    position: new AMap.LngLat(_that.placeLng, _that.placeLat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
											    title: _that.placeName
											});
											map.add(marker);
											_that.showmap = true
										},
									})		
								}
							  }
							
							  function onError (data) {
								  uni.getLocation({
								  	type: 'gcj02',
								  	geocode: true,
								  	isHighAccuracy: true,
								  	success: function (res) {
								  		_that.placeLng = res.longitude
								  		_that.placeLat =res.latitude
								  		uni.request({
								  			url: 'https://restapi.amap.com/v3/geocode/regeo?output=JSON&location='+_that.placeLng+','+_that.placeLat+'&key=c45ef8eb1919b2e8feaeea26b9414942&radius=10&extensions=all',   
								  			success: (zres) => { 
								  				_that.placeName = zres.data.regeocode.formatted_address
								  				var cpoint = [_that.placeLng, _that.placeLat]; //中心点坐标
								  				map.panTo(cpoint);
								  				
								  				var marker = new AMap.Marker({
								  				    position: new AMap.LngLat(_that.placeLng, _that.placeLat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
								  				    title: _that.placeName
								  				});
								  				map.add(marker);
												_that.showmap = true
								  			},
								  		})																		
								  	}
								  });	
							  }
							})
							//#endif
							//#ifndef H5
							uni.getLocation({
								type: 'gcj02',
								geocode: true,
								isHighAccuracy: true,
								success: function (res) {
									_that.placeLng = res.longitude
									_that.placeLat =res.latitude
									uni.request({
										url: 'https://restapi.amap.com/v3/geocode/regeo?output=JSON&location='+_that.placeLng+','+_that.placeLat+'&key=c45ef8eb1919b2e8feaeea26b9414942&radius=10&extensions=all',   
										success: (zres) => { 
											_that.placeName = zres.data.regeocode.formatted_address
											_that.showmap = true
										},
									})																		
								}
							});	
							//#endif
						}, 1000);	
						// }
					}
					
					changeEditor("title2","visitShowId",{
						"link":"../../public/pageSearch/pageSearch",
						"linkParam":{
							other:JSON.stringify({
								userId:_that.userId
							}),
							url:"visitSignIn/getVisitShowPager",
							cachename:_that.visitShowIdCacheKey,
							initload:true,
							searchfield: 'q',
							namefield:'visitShowCode',
							notefield:'customerName',
						}
					},null,mainData)
					
					changeEditor("title2","customerObjId",{
						"link":"../../public/pageSearch/pageSearch",
						"linkParam":{
							other:JSON.stringify({
								userId:_that.userId
							}),
							url:"visitSignIn/getCustomerShowPager",
							cachename:_that.customerObjIdCacheKey,
							initload:true,
							searchfield: 'q',
							namefield:'customerName',
							// suburl: 'visitSignIn/getDataByCustomerShowId',
							// subDataArr: JSON.stringify([{'customerShowId':'customerObjId'}]) 
						}
					},null,mainData)
					
					// changeEditor("title2", "customerName", {
					// 	link: '/pages/public/pageSearch/pageSearch',
					// 	"linkParam": {
					// 		prompt: "请选择",
					// 		namefield: "customerName",
					// 		extrafield: "startDate|stopDate",
					// 		initload: true,
					// 		searchByBackground: true,
					// 		searchfield: 'q',
					// 		url: "visitSignIn/getData",
					// 		cachename: _that.customerNameIdCacheKey
					// 	}
					// },null,mainData)
					
					// _that.signInTime()
					// changeEditor("title2","typeId",{
					// 	"linkParam":{
					// 		other:JSON.stringify({
					// 			code:'39081'
					// 		}),
					// 		url:"visitPlan/getCode",
					// 		cachename:_that.typeCacheKey,
					// 		initload:true,
					// 		namefield:'dicname'
					// 	}
					// },null,mainData)
					changeEditor("title2","typeId",{
						"linkParam":{
							other:JSON.stringify({
								code:'39081'
							}),
							url:"tsysdict/getComboTree",
							cachename:_that.typeCacheKey,
							initload:true,
							namefield:'text'
						}
					},null,mainData)
					changeEditor("title2","visitTargetIdStr",{
						"linkParam":{
							other:JSON.stringify({
								code:'39383'
							}),
							url:"tsysdict/getComboTree",
							cachename:_that.visitTargetIdStrCacheKey,
							initload:true,
							namefield:'text'
						}
					},null,mainData)
					changeEditor("title2","visitPreparationIdStr",{
						"linkParam":{
							other:JSON.stringify({
								code:'39384'
							}),
							url:"tsysdict/getComboTree",
							cachename:_that.visitPreparationIdStrCacheKey,
							initload:true,
							namefield:'text'
						}
					},null,mainData)
					changeEditor("title2","exchangePointIdStr",{
						"linkParam":{
							other:JSON.stringify({
								code:'39701'
							}),
							url:"tsysdict/getComboTree",
							cachename:_that.exchangePointIdStrCacheKey,
							initload:true,
							namefield:'text'
						}
					},null,mainData)
					// changeEditor('title2', 'typeId', 'data', configSelectData(res[1], 'id', 'dicname'), mainData);
					
				},options)
			},
			bd_decrypt(bd_lng,bd_lat){//百度地图坐标转高德地图坐标
				var X_PI = (Math.PI * 3000.0) / 180.0;
				var x = bd_lng - 0.0065;
				var y = bd_lat - 0.006;
				var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
				var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI);
				var gg_lng = z * Math.cos(theta);
				var gg_lat = z * Math.sin(theta);
				return { lng: gg_lng, lat: gg_lat };
			},
			signInTime(){
				setTimeout(() => {
				// this.formdata.signInTime = this.nowTime()
				this.$refs.autoform.formdata.signInTime = this.nowTime()
				}, 1000);	
			},
			nowTime(){
				var myDate = new Date();
				var year = myDate.getFullYear();
				var month = (myDate.getMonth()+1) < 10 ? '0'+(myDate.getMonth()+1) : (myDate.getMonth()+1);
				var day = myDate.getDate() < 10 ? '0'+myDate.getDate() : myDate.getDate();
				var hours = myDate.getHours() < 10 ? '0'+myDate.getHours() : myDate.getHours();
				var minutes = myDate.getMinutes() < 10 ? '0'+myDate.getMinutes() : myDate.getMinutes();
				// var seconds = myDate.getSeconds() < 10 ? '0'+myDate.getSeconds() : myDate.getSeconds();
				return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes;
			},
			preview(){
			    uni.previewImage({
			        urls:[this.src],
			        current:0
			    })
			},
			takePhone(){
				let that = this;
				that.haspic = false
				uni.chooseImage({
				    count: 1,
				    sourceType: ['camera'], //使用相机
				    success: function (res) {
						let quality = 1;
						if(res.tempFiles[0].size/(1024*1024)>1){
							quality = 0.8;
						}
						let ntime = that.nowTime()
						// that.src = res.tempFilePaths[0]
						uni.getImageInfo({
						    src: res.tempFilePaths[0],
						    success: (ress) => {
						        that.w = ress.width/3+'px';
						        that.h = ress.height/3+'px';
								setTimeout(() => {
									let ctx = uni.createCanvasContext('firstCanvas');    /** 创建画布 */
									//将图片src放到cancas内，宽高为图片大小
									ctx.drawImage(res.tempFilePaths[0], 0, 0, ress.width / 3, ress.height / 3)
									ctx.setFontSize(32) 
									ctx.setFillStyle('#8a2929')
									ctx.rotate(30 * Math.PI / 180);
									let textToWidth = ress.width / 3 * 0.5; 
									let textToHeight = ress.height / 3 * 0.3;
									ctx.fillText(ntime, textToWidth, textToHeight)  
									/** 除了上面的文字水印，这里也可以加入图片水印 */
									//ctx.drawImage('/static/watermark.png', 0, 0, ress.width / 3, ress.height / 3)
									ctx.draw(false,()=>{
										setTimeout(() => {
											uni.canvasToTempFilePath({
												canvasId: 'firstCanvas',
												quality: quality,
												success: (res1) => {
													that.haspic = true
													that.src=res1.tempFilePath;
													
													that.om.uploadFile('/uploadFileData/uploadInterimFile.do', that.src, null,{
														key: that.fileKey
													}, null, false).then(res => {
														let d = JSON.parse(res)
														if(d.succeed){
															let bottomFileList = []
															bottomFileList.push({
																uploadName: d.value.uploadName,
																fileName: d.value.uploadName,
																fileSaveName: d.value.saveName,
																fileUrl: d.value.fileUrl
															})
															that.formdata.updateBottomFileFlag= true
															that.formdata.bottomFileListStr = JSON.stringify(bottomFileList || []) || ''
															
														}
													})
												}
											});
										}, 100);
									});
								}, 100);
						    }
						})
				    },
					fail: function (res) {
						console.log(res)
					}
				});
			},
			signPlace(){
				let _that = this
				uni.navigateTo({
					url: "/pages/form/mar-yxhd-visitSign/visit-sign-appmap?placeLng="+_that.placeLng+"&placeLat="+_that.placeLat+"&placeName="+_that.placeName +"&distance=" + _that.distanceValue
				});
				// //#ifdef H5
				// uni.navigateTo({
				// 	url: "/pages/form/mar-yxhd-visitSign/visit-sign-map?placeLng="+_that.placeLng+"&placeLat="+_that.placeLat+"&placeName="+_that.placeName
				// });
				// //#endif
				// //#ifndef H5
				// uni.navigateTo({
				// 	url: "/pages/form/mar-yxhd-visitSign/visit-sign-appmap?placeLng="+_that.placeLng+"&placeLat="+_that.placeLat+"&placeName="+_that.placeName
				// });
				// //#endif
			},
			formSubmit() {
				let _that = this;
				
				if(_that.src && _that.haspic){
					if(_that.placeLng && _that.placeLat){
						// _that.om.uploadFile('/uploadFileData/uploadInterimFile.do', _that.src, null,{
						// 	key: _that.fileKey
						// }, null, false).then(res => {
						// 	let d = JSON.parse(res)
						// 	if(d.succeed){
						// 		let bottomFileList = []
						// 		bottomFileList.push({
						// 			uploadName: d.value.uploadName,
						// 			fileName: d.value.uploadName,
						// 			fileSaveName: d.value.saveName,
						// 			fileUrl: d.value.fileUrl
						// 		})
						// 		_that.formdata.updateBottomFileFlag= true
						// 		_that.formdata.bottomFileListStr = JSON.stringify(bottomFileList || []) || ''
								_that.formdata.lng = _that.placeLng
								_that.formdata.lat = _that.placeLat
								_that.formdata.signInAddress = _that.placeName
								// if(_that.isnewcustomer){
								// 	_that.formdata.customerNameId = 0
								// }
								_that.om.formSave('visitSignIn/doAdd',_that.formdata,_that)
						// 	}
						// })
					}else{
						_that.om.toast('请选择签到地址后再进行提交！')
					}
				}else{
					_that.om.toast('请先进行拍照')
				}
			},
			changeAuth(){
				
			}
		},
		onLoad(options) {
			let _that = this
			
			//#ifndef H5	
			uni.getLocation({
				type: 'wgs84',
				geocode: true,
				isHighAccuracy: true,
				success: function (res) {
					_that.placeLng = res.longitude
					_that.placeLat =res.latitude
					uni.request({
					    url: 'https://restapi.amap.com/v3/geocode/regeo?output=JSON&location='+res.longitude+','+res.latitude+'&key=c45ef8eb1919b2e8feaeea26b9414942&radius=1000&extensions=all',   
					    success: (zres) => { 
							_that.placeName = zres.data.regeocode.formatted_address
							_that.showmap = true
						},
					})
				}
			});
			setTimeout(()=>{
				_that.$refs['authpup'].open();
			},500)
			//#endif

			//#ifdef H5
			var url = 'https://webapi.amap.com/maps?v=1.4.15&key=92bfa8b848fb3fbaf2b4d5fa40447225';
			var jsapi = document.createElement('script');
			jsapi.charset = 'utf-8';
			jsapi.src = url;
			document.head.appendChild(jsapi);
			//#endif
			_that.initLoad(options)
			uni.setStorageSync('visitSignMarkerKey', '')
			sessionStorage.setItem("visitSignh5Key", '')
		},
		onShow() {
			let _that = this	
			for (var fieldId in _that.subEditorObj) {
				var editor = _that.subEditorObj[fieldId];
				uni.getStorage({
					key: getWorkCacheKey(fieldId),
					success: function(res) {
						for(let item of res.data){
							if(item.fileList ==""){
								item.fileList = []
							}
						}
						editor.workList = res.data;
						uni.removeStorage({
							key: getWorkCacheKey(fieldId)
						});
					}
				});
			}
			
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.visitShowIdCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.visitShowId = d.visitShowId
							formdata.visitShowCode = d.visitShowCode
							formdata.customerObjId = d.customerObjId
							formdata.customerCode = d.customerCode
							formdata.customerShortName = d.customerShortName
							formdata.customerId = d.customerId
							formdata.customerName = d.customerName
							formdata.developmentDate = d.developmentDate
							formdata.transactiontatusId = d.transactiontatusId
							formdata.transactiontatus = d.transactiontatus
							formdata.customerOwnerId = d.customerOwnerId
							formdata.customerOwner = d.customerOwner
							formdata.instId = d.instId
							formdata.inst = d.inst
							formdata.planRemark = d.planRemark
							formdata.problemRemark = d.problemRemark
							formdata.typeId = d.typeId
							formdata.type = d.type
							formdata.startDate = d.startDate
							formdata.timeRangeId = d.timeRangeId
							formdata.timeRangeName = d.timeRangeName
							formdata.stopDate = d.stopDate
							formdata.peopleId = d.peopleId
							formdata.people = d.people
							formdata.orderDate = d.orderDate
							formdata.visitTargetIdStr = d.visitTargetIdStr
							formdata.visitTargetNameStr = d.visitTargetNameStr
							formdata.visitPreparationIdStr = d.visitPreparationIdStr
							formdata.visitPreparationNameStr = d.visitPreparationNameStr
							formdata.exchangePointIdStr = d.exchangePointIdStr
							formdata.exchangePointNameStr = d.exchangePointNameStr
							_that.$refs.autoform.changeEditor("title2","typeId","type","labelbox")
							_that.$refs.autoform.changeEditor("title2","visitTargetIdStr","type","labelbox")
							_that.$refs.autoform.changeEditor("title2","visitPreparationIdStr","type","labelbox")
							_that.$refs.autoform.changeEditor("title2","exchangePointIdStr","type","labelbox")
							uni.removeStorage({
								key:_that.visitShowIdCacheKey
							})
						}
					}
				});
				uni.getStorage({
					key:_that.customerObjIdCacheKey,
					success:(res)=>{
						if(res.data){
							_that.$refs.autoform.clear('title2', 'visitShowId');
							
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.customerObjId = d.customerObjId
							formdata.customerCode = d.customerCode
							formdata.customerShortName = d.customerShortName
							formdata.customerId = d.customerId
							formdata.customerName = d.customerName
							formdata.developmentDate = d.developmentDate
							formdata.transactiontatusId = d.transactiontatusId
							formdata.transactiontatus = d.transactiontatus
							formdata.customerOwnerId = d.customerOwnerId
							formdata.customerOwner = d.customerOwner
							formdata.instId = d.instId
							formdata.inst = d.inst
							formdata.planRemark = d.planRemark
							formdata.problemRemark = d.problemRemark
							formdata.typeId = d.typeId
							formdata.type = d.type
							formdata.startDate = d.startDate
							formdata.timeRangeId = d.timeRangeId
							formdata.timeRangeName = d.timeRangeName
							formdata.stopDate = d.stopDate
							formdata.peopleId = d.peopleId
							formdata.people = d.people
							formdata.orderDate = d.orderDate
							_that.$refs.autoform.changeEditor('title2', 'typeId', {
								initSelect: d
							})
							formdata.visitTargetIdStr = d.visitTargetIdStr
							formdata.visitTargetNameStr = d.visitTargetNameStr
							_that.$refs.autoform.changeEditor('title2', 'visitTargetIdStr', {
								initSelect: d
							})
							formdata.visitPreparationIdStr = d.visitPreparationIdStr
							formdata.visitPreparationNameStr = d.visitPreparationNameStr
							_that.$refs.autoform.changeEditor('title2', 'visitPreparationIdStr', {
								initSelect: d
							})
							
							formdata.exchangePointIdStr = d.exchangePointIdStr
							formdata.exchangePointNameStr = d.exchangePointNameStr
							_that.$refs.autoform.changeEditor('title2', 'exchangePointIdStr', {
								initSelect: d
							})
							
							_that.$refs.autoform.changeEditor("title2","typeId","type","multilinkbox")
							_that.$refs.autoform.changeEditor("title2","visitTargetIdStr","type","multilinkbox")
							_that.$refs.autoform.changeEditor("title2","visitPreparationIdStr","type","multilinkbox")
							_that.$refs.autoform.changeEditor("title2","exchangePointIdStr","type","multilinkbox")
							uni.removeStorage({
								key:_that.customerObjIdCacheKey
							})
						}
					}
				});
				// uni.getStorage({
				// 	key: _that.customerNameIdCacheKey,
				// 	success: function(res) {
				// 		if(res.data){
				// 			let d = res.data
				// 			var formdata  = _that.$refs.autoform.formdata
				// 			if(Object.prototype.toString.call(d) != "[object Object]"){
				// 				formdata.customerName = d
				// 				_that.isnewcustomer = true
				// 			}else{
				// 				_that.isnewcustomer = false
				// 				formdata.customerId = d.customerId
				// 				formdata.customerName = d.customerName
				// 				formdata.customerNameId = d.customerNameId
				// 				formdata.customerObjId = d.customerObjId
				// 				formdata.visitPlanDataId = d.visitPlanDataId
				// 				formdata.customerShortName = d.customerShortName
				// 				formdata.customerOwner = d.customerOwner
				// 				formdata.customerOwnerId = d.customerOwnerId
				// 				formdata.inst = d.inst
				// 				formdata.instId = d.instId
				// 				formdata.type = d.type
				// 				formdata.typeId = d.typeId
				// 				formdata.visitPurpose = d.visitPurpose
				// 				formdata.transactiontatusId = d.transactiontatusId
				// 				formdata.transactiontatus = d.transactiontatus
				// 				// _that.$refs.autoform.changeEditor('title2', 'typeId', {
				// 				// 	initSelect: d
				// 				// })
				// 			}
				// 			uni.removeStorage({
				// 				key: _that.customerNameIdCacheKey
				// 			});
				// 		}
				// 	},
				// });
				uni.getStorage({
					key:_that.typeCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.typeId = d.map(e=>e.id).join(',')
							formdata.type = d.map(e=>e.text).join(',')
							_that.$refs.autoform.changeEditor('title2', 'typeId', {
								initSelect: d
							})
							uni.removeStorage({
								key:_that.typeCacheKey
							})
						}
					}
				});
				uni.getStorage({
					key:_that.visitTargetIdStrCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.visitTargetIdStr = d.map(e=>e.id).join(',')
							formdata.visitTargetNameStr = d.map(e=>e.text).join(',')
							_that.$refs.autoform.changeEditor('title2', 'visitTargetIdStr', {
								initSelect: d
							})
							uni.removeStorage({
								key:_that.visitTargetIdStrCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key:_that.visitPreparationIdStrCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.visitPreparationIdStr = d.map(e=>e.id).join(',')
							formdata.visitPreparationNameStr = d.map(e=>e.text).join(',')
							_that.$refs.autoform.changeEditor('title2', 'visitPreparationIdStr', {
								initSelect: d
							})
							uni.removeStorage({
								key:_that.visitPreparationIdStrCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key:_that.exchangePointIdStrCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.exchangePointIdStr = d.map(e=>e.id).join(',')
							formdata.exchangePointNameStr = d.map(e=>e.text).join(',')
							_that.$refs.autoform.changeEditor('title2', 'exchangePointIdStr', {
								initSelect: d
							})
							uni.removeStorage({
								key:_that.exchangePointIdStrCacheKey
							})
						}
					}
				})
			}
			
			_that.markerDesc = uni.getStorageSync('visitSignMarkerKey') || sessionStorage.getItem('visitSignh5Key')
			if(_that.markerDesc){
				let markerDescObj = JSON.parse(_that.markerDesc)
				_that.placeLng = markerDescObj.lng
				_that.placeLat = markerDescObj.lat
				_that.placeName = markerDescObj.name
				
				//#ifdef H5
				var cpoint = [_that.placeLng, _that.placeLat]; //中心点坐标
				var map = new AMap.Map('container',{
					zoom: 16, //设置地图的缩放级别
					zoomEnable: false,
					dragEnable: false,
					touchZoom: false,
					center: cpoint
				});
				
				var marker = new AMap.Marker({
					position: new AMap.LngLat(_that.placeLng, _that.placeLat),   // 经纬度对象，也可以是经纬度构成的一维数组[116.39, 39.9]
					title: _that.placeName
				});
				map.add(marker);
				
				//#endif
			}
		},
	}
</script>
<style lang="scss" scoped>
	.cont{
		.fl{
			float: left;
			span{
				color: red;
			}
		}
		.fr{
			float: right;
			text-align: right;
		}
	}
	image{
		will-change: transform
	}
	.map{
		width: 100%;
		height: 100px;
		background: #eaeaea;
	}
</style>                                                                                                                                                                                                                                                                                                                  
